//
//  ByDocumentaryListContentView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/21.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryListContentView.h"
#import "ByBetSecretView.h"


@implementation ByDocumentaryListContentView

- (id)init{
    self = [super init];
    if (self) {
        
        UIView *grayView = [[UIView alloc] init];
        [self addSubview:grayView];
        grayView.backgroundColor = rgba(255, 248, 249, 1);
        grayView.layer.borderColor = BY_LINE_COLOR.CGColor;
        grayView.layer.borderWidth = 1;
        self.grayView = grayView;
        
        UIImageView *ballView = [[UIImageView alloc] init];
        [self addSubview:ballView];
        [ballView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.top.equalTo(self).offset(5);
            make.size.mas_equalTo(CGSizeMake(22, 22));
        }];
        ballView.image = [UIImage imageNamed:@"zuqiu足球"];
        self.ballView = ballView;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        [grayView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(grayView).offset(22);
            make.top.equalTo(grayView).offset(13);
            make.width.mas_equalTo(@120);
            make.height.mas_equalTo(@15);
        }];
        titleLabel.font = FONT(13);
        titleLabel.textColor = [UIColor colorWithHexString:@"#FA2167"];
        titleLabel.text = @"竞彩足球 12589期";
        self.titleLabel = titleLabel;
        
        UILabel *wayLabel = [[UILabel alloc] init];
        [grayView addSubview:wayLabel];
        [wayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(grayView).offset(-17);
            make.top.equalTo(titleLabel.mas_top).offset(0);
            make.height.mas_equalTo(@15);
            make.left.equalTo(titleLabel.mas_right).offset(10);
        }];
        wayLabel.font = FONT(13);
        wayLabel.textColor  = [UIColor colorWithHexString:@"#FA2167"];;
        wayLabel.text = @"2串1";
        wayLabel.hidden = YES;
        wayLabel.textAlignment = NSTextAlignmentRight;
        self.wayLabel = wayLabel;
        
        CGFloat width = SCREEN_WIDTH - 12 - 30;
        ByDocumentaryFourValue *valueView = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(0, 41,width , 35)];
        [self.grayView addSubview:valueView];
        valueView.valueLabel1.text = @"场次";
        valueView.valueLabel2.text = @"主队";
        valueView.valueLabel3.text = @"客队";
        valueView.valueLabel4.text = @"投注内容";
        self.valueView = valueView;

        ByDottedLineView *line = [[ByDottedLineView alloc] init];
        line.direction = DottedLineViewDirectionHorizontalFromRight;
        line.lineColor = BY_LINE_COLOR;
        line.lengthPattern = @[@4, @3];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
            make.height.mas_equalTo(@1);
        }];
        self.line = line;
        
      
        
        
        
        
    }
    return self;
}

- (void)setIsUser:(BOOL)isUser{
    _isUser = isUser;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    CGFloat width = SCREEN_WIDTH - 12 - 30;
    CGFloat top = 41;
    NSArray *dataArray;
    
    if (netModel.public_type.integerValue == 2 || (netModel.public_type.integerValue == 1 && netModel.is_result.integerValue == 1)) {
        dataArray = netModel.ball_infoArray;
    }else{
        dataArray = @[@""];
    }
    
    
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self).offset(15);
        make.height.mas_equalTo(@(41 + dataArray.count * 35 + 35));
    }];
    //公开才展示
    if (netModel.public_type.integerValue == 2 || (netModel.public_type.integerValue == 1 && netModel.is_result.integerValue == 1)) {
    
    for (int i = 0; i < dataArray.count; i++) {
        top = top + 35;
        ByNetModel *netModel = [dataArray objectAtIndex:i];
        ByDocumentaryFourValue *valueView = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(0, top,width , 35)];
        valueView.valueLabel1.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel2.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel3.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel4.textColor = [UIColor colorWithHexString:@"#666666"];
        [self.grayView addSubview:valueView];
        valueView.valueLabel1.text = [NSString stringWithFormat:@"%@",netModel.num];
        if (_isUser) {
            valueView.valueLabel2.text = [NSString stringWithFormat:@"%@/%@", netModel.a_cn,netModel.h_cn];
            valueView.valueLabel3.text = netModel.planDic[netModel.p_time];
            
            if (netModel.is_result.integerValue == 0) {
                valueView.valueLabel4.text = @"未开奖";
                
            }else{
                valueView.valueLabel4.text = netModel.final_score;
                if (_netModel.lottery_type.integerValue == 2) {
                valueView.valueLabel4.text = netModel.game_Result;
                }
            }
        }else{
            valueView.valueLabel2.text = netModel.a_cn;
            valueView.valueLabel3.text = netModel.h_cn;
            valueView.valueLabel4.text = netModel.planDic[netModel.p_time];
        }
            
        
      
    }
    
    for (int i = 0; i< dataArray.count + 2; i++) {
        UILabel *centerLine = [[UILabel alloc] init];
        [self.grayView addSubview:centerLine];
        [centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.grayView).offset(0);
            make.right.equalTo(self.grayView).offset(0);
            make.bottom.equalTo(self.grayView).offset(-35 * i);
            make.height.mas_equalTo(@1);
        }];
        centerLine.backgroundColor = BY_LINE_COLOR;
    }
    

    CGFloat height = dataArray.count * 35 + 35;
    width = width / 4.0;
    for (int i = 1; i < 4; i++) {
        UILabel *line = [[UILabel alloc] init];
        [self.grayView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.grayView).offset(width * i);
            make.bottom.equalTo(self.grayView).offset(0);
            make.size.mas_equalTo(CGSizeMake(1, height));
        }];
        line.backgroundColor = BY_LINE_COLOR;
    }
         
    }else{
        CGFloat width = SCREEN_WIDTH - 12 - 30;
        ByBetSecretView *secretView = [[ByBetSecretView alloc] initWithFrame:CGRectMake(0, 41, width, 69)];
        [self.grayView addSubview:secretView];
        if (netModel.public_type.integerValue == 0) {
            secretView.titleLabel.text= @"投注方案保密";
        }else{
            secretView.titleLabel.text = @"投注方案保密，开奖后可公开";
        }
        
        
    }
    
    if (netModel.lottery_type.integerValue == 1) {
        self.titleLabel.text = @"足球竞彩";
    }else if (netModel.lottery_type.integerValue == 2){
        self.titleLabel.text = @"篮球竞彩";
    }
    
}


@end
